<template>
  <a-modal
    v-model:open="openForm"
    width="60vw"
    :title="`微信${props.rowData.productName ? '-' + props.rowData.productName : ''}`"
    @ok="handleOk"
    @cancel="handleCancel"
  >
    <div class="p-y-20px">
      <group-title class="pb-0.5" :iconOptions="{ class: 'text-blue-400' }" v-if="props.formType == 'updateScene'">经营资料</group-title>
      <a-steps :current="current" size="small" :items="stepsItems" v-else />
    </div>
    <a-form ref="formRef" :model="formData" v-bind="formOptions" :rules="props.formType == 'view' ? {} : rules" :disabled="props.formType == 'view'">
      <template v-if="current === 0">
        <a-row :gutter="16">
          <a-col class="gutter-row" :span="24">
            <group-title class="pb-0.5" :iconOptions="{ class: 'text-blue-400' }">基本信息</group-title>
          </a-col>
          <template v-for="(item, index) in jIdentitiesList" :key="`${item?.userType}` - `${index}`">
            <template v-if="item?.userType == 0">
              <a-col class="gutter-row" :span="12">
                <a-form-item label="超级管理员类型:" :name="['jIdentitiesList', index, 'idHolderType']">
                  <a-select v-model:value="item.idHolderType" :options="HOLDER_TYPE" placeholder="请选择" />
                </a-form-item>
              </a-col>
              <a-col class="gutter-row" :span="12">
                <a-form-item label="超级管理员姓名:" :name="['jIdentitiesList', index, 'idDocName']">
                  <a-input v-model:value="item.idDocName" placeholder="请输入" />
                </a-form-item>
              </a-col>
              <a-col class="gutter-row" :span="12">
                <a-form-item label="超级管理员证件类型:" :name="['jIdentitiesList', index, 'idDocType']">
                  <a-select v-model:value="item.idDocType" :options="DOC_TYPE" placeholder="请选择" />
                </a-form-item>
              </a-col>
              <a-col class="gutter-row" :span="12">
                <a-form-item label="超级管理员身份证件号码:" :name="['jIdentitiesList', index, 'idDocNumber']">
                  <a-input v-model:value="item.idDocNumber" placeholder="请输入" />
                </a-form-item>
              </a-col>
              <a-col class="gutter-row" :span="12">
                <a-form-item label="证件正面照片" :name="['jIdentitiesList', index, 'idDocCopy']">
                  <a-upload
                    v-model:file-list="item.idDocCopy"
                    name="idDocCopy"
                    :max-count="1"
                    :custom-request="(file) => uploadFunc(file, `jIdentitiesList.${index}.idDocCopy`)"
                    :accept="limitUpload['comment'].fileType.toString()"
                    :before-upload="(file, fileList) => beforeUpload(file, fileList, 'idDocCopy')"
                    :headers="{
                      authorization: 'authorization-text',
                    }"
                  >
                    <a-button>
                      <upload-outlined />
                      点击上传
                    </a-button>
                  </a-upload>
                </a-form-item>
              </a-col>
              <a-col class="gutter-row" :span="12">
                <a-form-item label="证件反面照片:" :name="['jIdentitiesList', index, 'idDocCopyBack']">
                  <a-upload
                    v-model:file-list="item.idDocCopyBack"
                    name="idDocCopyBack"
                    :max-count="1"
                    :custom-request="(file) => uploadFunc(file, `jIdentitiesList.${index}.idDocCopyBack`)"
                    :accept="limitUpload['comment'].fileType.toString()"
                    :before-upload="(file, fileList) => beforeUpload(file, fileList, 'idDocCopyBack')"
                    :headers="{
                      authorization: 'authorization-text',
                    }"
                  >
                    <a-button>
                      <upload-outlined />
                      点击上传
                    </a-button>
                  </a-upload>
                </a-form-item>
              </a-col>
              <a-col class="gutter-row" :span="12">
                <a-form-item label="证件有效期开始时间:" :name="['jIdentitiesList', index, 'idDocPeriodBegin']">
                  <a-date-picker
                    class="w-full"
                    v-model:value="item.idDocPeriodBegin"
                    :disabled-date="(dataVal) => dataVal && item.idDocPeriodEnd && dataVal + 8.64e7 - 1000 >= new Date(item.idDocPeriodEnd).getTime()"
                    :valueFormat="'YYYY-MM-DD'"
                  />
                </a-form-item>
              </a-col>
              <a-col class="gutter-row" :span="12">
                <a-form-item label="证件有效期结束时间:" :name="['jIdentitiesList', index, 'idDocPeriodEnd']">
                  <a-date-picker
                    class="w-full"
                    v-model:value="item.idDocPeriodEnd"
                    :disabled-date="(dataVal) => dataVal && item.idDocPeriodBegin && dataVal <= new Date(item.idDocPeriodBegin).getTime()"
                    :valueFormat="'YYYY-MM-DD'"
                  />
                </a-form-item>
              </a-col>
              <a-col class="gutter-row" :span="12">
                <a-form-item label="业务办理授权函:" :name="['jIdentitiesList', index, 'businessAuthorizationLetter']">
                  <a-upload
                    v-model:file-list="item.businessAuthorizationLetter"
                    name="businessAuthorizationLetter"
                    :max-count="1"
                    :custom-request="(file) => uploadFunc(file, `jIdentitiesList.${index}.businessAuthorizationLetter`)"
                    :accept="limitUpload['comment'].fileType.toString()"
                    :before-upload="(file, fileList) => beforeUpload(file, fileList, 'businessAuthorizationLetter')"
                    :headers="{
                      authorization: 'authorization-text',
                    }"
                  >
                    <a-button>
                      <upload-outlined />
                      点击上传
                    </a-button>
                  </a-upload>
                </a-form-item>
              </a-col>
            </template>
          </template>
          <a-col class="gutter-row" :span="12">
            <a-form-item label="联系手机号:" :name="['jSubject', 'phone']">
              <a-input v-model:value="jSubject.phone" placeholder="请输入" />
            </a-form-item>
          </a-col>
          <a-col class="gutter-row" :span="12">
            <a-form-item label="联系邮箱:" :name="['jSubject', 'email']">
              <a-input v-model:value="jSubject.email" placeholder="请输入" />
            </a-form-item>
          </a-col>
        </a-row>
      </template>
      <template v-if="current === 1">
        <a-row :gutter="16">
          <a-col class="gutter-row" :span="12">
            <a-form-item label="主体类型:" :name="['jSubject', 'subjectType']">
              <a-select v-model:value="jSubject.subjectType" :options="SUBJECT_TYPE" placeholder="请选择" />
            </a-form-item>
          </a-col>
          <a-form-item label="是否是金融机构:" name="financeInstitution">
            <a-radio-group v-model:value="jSubject.financeInstitution" :options="YES_OR_NO" />
          </a-form-item>
          <template v-if="jSubject.subjectType == 0 || jSubject.subjectType == 1">
            <a-col :span="24">
              <group-title class="pb-0.5" :iconOptions="{ class: 'text-blue-400' }">营业信息</group-title>
            </a-col>
            <a-col class="gutter-row" :span="12">
              <a-form-item label="注册号/统一社会信用代码:" :name="['jSubject', 'businessLicenseNo']">
                <a-input v-model:value="jSubject.businessLicenseNo" placeholder="请输入" />
              </a-form-item>
            </a-col>
            <a-col class="gutter-row" :span="12">
              <a-form-item label="个体户经营者/法人姓名:" :name="['jSubject', 'name']">
                <a-input v-model:value="jSubject.name" placeholder="请输入" />
              </a-form-item>
            </a-col>
            <a-col class="gutter-row" :span="12">
              <a-form-item label="注册地址:" :name="['jSubject', 'businessLicenseAddress']">
                <a-input v-model:value="jSubject.businessLicenseAddress" placeholder="请输入" />
              </a-form-item>
            </a-col>
            <a-col class="gutter-row" :span="12">
              <a-form-item label="商户名称:" :name="['jSubject', 'businessLicenseName']">
                <a-input v-model:value="jSubject.businessLicenseName" placeholder="请输入" />
              </a-form-item>
            </a-col>
            <a-col class="gutter-row" :span="12">
              <a-form-item label="营业执照照片:" :name="['jSubject', 'businessLicensePic']">
                <a-upload
                  v-model:file-list="jSubject.businessLicensePic"
                  :max-count="1"
                  name="businessLicensePic"
                  :custom-request="(file) => uploadFunc(file, `jSubject.businessLicensePic`)"
                  :accept="limitUpload['comment'].fileType.toString()"
                  :before-upload="(file, fileList) => beforeUpload(file, fileList, 'businessLicensePic')"
                  :headers="{
                    authorization: 'authorization-text',
                  }"
                >
                  <a-button>
                    <upload-outlined />
                    点击上传
                  </a-button>
                </a-upload>
              </a-form-item>
            </a-col>
          </template>
          <template v-if="jSubject.financeInstitution == 1">
            <a-col class="gutter-row" :span="12">
              <a-form-item label="金融机构类型:" :name="['jSubject', 'financeType']">
                <a-select v-model:value="jSubject.financeType" :options="FINANCE_TYPE" placeholder="请选择" />
              </a-form-item>
            </a-col>
            <a-col class="gutter-row" :span="12" v-if="jSubject.subjectType == 0 || jSubject.subjectType == 1">
              <a-form-item label="金融机构许可证图片:" :name="['jSubject', 'financeLicensePics']">
                <a-upload
                  v-model:file-list="jSubject.financeLicensePics"
                  :max-count="1"
                  name="financeLicensePics"
                  :custom-request="(file) => uploadFunc(file, 'jSubject.financeLicensePics')"
                  :accept="limitUpload['comment'].fileType.toString()"
                  :before-upload="(file, fileList) => beforeUpload(file, fileList, 'financeLicensePics')"
                  :headers="{
                    authorization: 'authorization-text',
                  }"
                >
                  <a-button>
                    <upload-outlined />
                    点击上传
                  </a-button>
                </a-upload>
              </a-form-item>
            </a-col>
          </template>
          <a-col :span="24">
            <group-title class="pb-0.5" :iconOptions="{ class: 'text-blue-400' }">
              经营者/法人信息
              <a-tooltip placement="top">
                <template #title>
                  <div>1个体户：请上传经营者的身份证件；</div>
                  <div>2、企业/社会组织：请上传法人的身份证件；</div>
                  <div>3、政府机关/事业单位：请上传法人/经办人的身份证件</div>
                </template>
                <QuestionCircleOutlined />
              </a-tooltip>
            </group-title>
          </a-col>

          <template v-for="(item, index) in jIdentitiesList" :key="`${item?.userType}` - `${index}`">
            <template v-if="item?.userType == 1">
              <a-col class="gutter-row" :span="12">
                <a-form-item label="证件持有人类型:" :name="['jIdentitiesList', index, 'idHolderType']">
                  <a-select v-model:value="item.idHolderType" :options="HOLDER_TYPE" placeholder="请选择" />
                </a-form-item>
              </a-col>
              <a-col class="gutter-row" :span="12">
                <a-form-item label="证件类型:" :name="['jIdentitiesList', index, 'idDocType']">
                  <a-select v-model:value="item.idDocType" :options="DOC_TYPE" placeholder="请选择" />
                </a-form-item>
              </a-col>
              <a-col class="gutter-row" :span="12">
                <a-form-item label="证件姓名:" :name="['jIdentitiesList', index, 'idDocName']">
                  <a-input v-model:value="item.idDocName" placeholder="请输入" />
                </a-form-item>
              </a-col>
              <a-col class="gutter-row" :span="12">
                <a-form-item label="法定代表人说明函:" :name="['jIdentitiesList', index, 'authorizeLetterCopy']">
                  <a-upload
                    v-model:file-list="item.authorizeLetterCopy"
                    name="authorizeLetterCopy"
                    :max-count="1"
                    :custom-request="(file) => uploadFunc(file, `jIdentitiesList.${index}.authorizeLetterCopy`)"
                    :accept="limitUpload['comment'].fileType.toString()"
                    :before-upload="(file, fileList) => beforeUpload(file, fileList, 'authorizeLetterCopy')"
                    :headers="{
                      authorization: 'authorization-text',
                    }"
                  >
                    <a-button>
                      <upload-outlined />
                      点击上传
                    </a-button>
                  </a-upload>
                </a-form-item>
              </a-col>
              <a-col class="gutter-row" :span="12">
                <a-form-item label="经营者/法人是否为受益人:" :name="['jIdentitiesList', index, 'owner']">
                  <a-radio-group v-model:value="item.owner" :options="YES_OR_NO" />
                </a-form-item>
              </a-col>
              <a-col class="gutter-row" :span="12">
                <a-form-item label="证件号码:" :name="['jIdentitiesList', index, 'idDocNumber']">
                  <a-input v-model:value="item.idDocNumber" placeholder="请输入" />
                </a-form-item>
              </a-col>
              <a-col class="gutter-row" :span="12">
                <a-form-item label="证件居住地址:" :name="['jIdentitiesList', index, 'idDocAddress']">
                  <a-input v-model:value="item.idDocAddress" placeholder="请输入" />
                </a-form-item>
              </a-col>
              <a-col class="gutter-row" :span="12">
                <a-form-item label="证件有效期开始时间:" :name="['jIdentitiesList', index, 'idDocPeriodBegin']">
                  <a-date-picker
                    class="w-full"
                    v-model:value="item.idDocPeriodBegin"
                    :disabled-date="(dataVal) => dataVal && item.idDocPeriodEnd && dataVal + 8.64e7 - 1000 >= new Date(item.idDocPeriodEnd).getTime()"
                    :valueFormat="'YYYY-MM-DD'"
                  />
                </a-form-item>
              </a-col>
              <a-col class="gutter-row" :span="12">
                <a-form-item label="证件有效期结束时间:" :name="['jIdentitiesList', index, 'idDocPeriodEnd']">
                  <a-date-picker
                    class="w-full"
                    v-model:value="item.idDocPeriodEnd"
                    :disabled-date="(dataVal) => dataVal && item.idDocPeriodBegin && dataVal <= new Date(item.idDocPeriodBegin).getTime()"
                    :valueFormat="'YYYY-MM-DD'"
                  />
                </a-form-item>
              </a-col>
              <a-col class="gutter-row" :span="12">
                <a-form-item label="证件正面照片" :name="['jIdentitiesList', index, 'idDocCopy']">
                  <a-upload
                    v-model:file-list="item.idDocCopy"
                    name="idDocCopy"
                    :max-count="1"
                    :custom-request="(file) => uploadFunc(file, `jIdentitiesList.${index}.idDocCopy`)"
                    :accept="limitUpload['comment'].fileType.toString()"
                    :before-upload="(file, fileList) => beforeUpload(file, fileList, 'idDocCopy')"
                    :headers="{
                      authorization: 'authorization-text',
                    }"
                  >
                    <a-button>
                      <upload-outlined />
                      点击上传
                    </a-button>
                  </a-upload>
                </a-form-item>
              </a-col>
              <a-col class="gutter-row" :span="12">
                <a-form-item label="证件反面照片:" :name="['jIdentitiesList', index, 'idDocCopyBack']">
                  <a-upload
                    v-model:file-list="item.idDocCopyBack"
                    name="idDocCopyBack"
                    :max-count="1"
                    :custom-request="(file) => uploadFunc(file, `jIdentitiesList.${index}.idDocCopyBack`)"
                    :accept="limitUpload['comment'].fileType.toString()"
                    :before-upload="(file, fileList) => beforeUpload(file, fileList, 'idDocCopyBack')"
                    :headers="{
                      authorization: 'authorization-text',
                    }"
                  >
                    <a-button>
                      <upload-outlined />
                      点击上传
                    </a-button>
                  </a-upload>
                </a-form-item>
              </a-col>
            </template>
          </template>

          <a-col class="gutter-row" :span="24">
            <a-button type="primary" size="small" @click="addJIdentities" class="m-r-2">
              <PlusOutlined />
              添加最终受益人信息
            </a-button>
            <a-tooltip placement="top">
              <template #title>
                <div>若经营者/法人不是最终受益所有人，则需补充受益所有人信息，最多上传4个</div>
                <div>若经营者/法人是最终受益所有人之一，可在此添加其他受益所有人信息，最多上传3个</div>
              </template>
              <QuestionCircleOutlined />
            </a-tooltip>
          </a-col>

          <template v-for="(item, index) in jIdentitiesList" :key="`${item?.userType}` - `${index}`">
            <template v-if="item?.userType == 2">
              <a-col class="gutter-row" :span="12">
                <a-form-item label="证件类型:" :name="['jIdentitiesList', index, 'idDocType']">
                  <a-select v-model:value="item.idDocType" :options="DOC_TYPE" placeholder="请选择" />
                </a-form-item>
              </a-col>
              <a-col class="gutter-row" :span="12">
                <a-form-item label="证件姓名:" :name="['jIdentitiesList', index, 'idDocName']">
                  <a-input v-model:value="item.idDocName" placeholder="请输入" />
                </a-form-item>
              </a-col>
              <a-col class="gutter-row" :span="12">
                <a-form-item label="证件号码:" :name="['jIdentitiesList', index, 'idDocNumber']">
                  <a-input v-model:value="item.idDocNumber" placeholder="请输入" />
                </a-form-item>
              </a-col>
              <a-col class="gutter-row" :span="12">
                <a-form-item label="证件居住地址:" :name="['jIdentitiesList', index, 'idDocAddress']">
                  <a-input v-model:value="item.idDocAddress" placeholder="请输入" />
                </a-form-item>
              </a-col>
              <a-col class="gutter-row" :span="12">
                <a-form-item label="证件有效期开始时间:" :name="['jIdentitiesList', index, 'idDocPeriodBegin']">
                  <a-date-picker
                    class="w-full"
                    v-model:value="item.idDocPeriodBegin"
                    :disabled-date="(dataVal) => dataVal && item.idDocPeriodEnd && dataVal + 8.64e7 - 1000 >= new Date(item.idDocPeriodEnd).getTime()"
                    :valueFormat="'YYYY-MM-DD'"
                  />
                </a-form-item>
              </a-col>
              <a-col class="gutter-row" :span="12">
                <a-form-item label="证件有效期结束时间:" :name="['jIdentitiesList', index, 'idDocPeriodEnd']">
                  <a-date-picker
                    class="w-full"
                    v-model:value="item.idDocPeriodEnd"
                    :disabled-date="(dataVal) => dataVal && item.idDocPeriodBegin && dataVal <= new Date(item.idDocPeriodBegin).getTime()"
                    :valueFormat="'YYYY-MM-DD'"
                  />
                </a-form-item>
              </a-col>
              <a-col class="gutter-row" :span="12">
                <a-form-item label="证件正面照片" :name="['jIdentitiesList', index, 'idDocCopy']">
                  <a-upload
                    v-model:file-list="item.idDocCopy"
                    name="idDocCopy"
                    :max-count="1"
                    :custom-request="(file) => uploadFunc(file, `jIdentitiesList.${index}.idDocCopy`)"
                    :accept="limitUpload['comment'].fileType.toString()"
                    :before-upload="(file, fileList) => beforeUpload(file, fileList, 'idDocCopy')"
                    :headers="{
                      authorization: 'authorization-text',
                    }"
                  >
                    <a-button>
                      <upload-outlined />
                      点击上传
                    </a-button>
                  </a-upload>
                </a-form-item>
              </a-col>
              <a-col class="gutter-row" :span="12">
                <a-form-item label="证件反面照片:" :name="['jIdentitiesList', index, 'idDocCopyBack']">
                  <a-upload
                    v-model:file-list="item.idDocCopyBack"
                    name="idDocCopyBack"
                    :max-count="1"
                    :custom-request="(file) => uploadFunc(file, `jIdentitiesList.${index}.idDocCopyBack`)"
                    :accept="limitUpload['comment'].fileType.toString()"
                    :before-upload="(file, fileList) => beforeUpload(file, fileList, 'idDocCopyBack')"
                    :headers="{
                      authorization: 'authorization-text',
                    }"
                  >
                    <a-button>
                      <upload-outlined />
                      点击上传
                    </a-button>
                  </a-upload>
                </a-form-item>
              </a-col>
              <a-col class="gutter-row m-b-6" :span="24">
                <a-button size="small" @click="delJIdentities(index)" class="w-full">
                  <MinusOutlined />
                  删减最终受益人信息
                </a-button>
              </a-col>
            </template>
          </template>
        </a-row>
      </template>
      <template v-if="current === 2">
        <a-row :gutter="16">
          <a-col class="gutter-row" :span="12">
            <a-form-item label="商户简称:" :name="['jSubject', 'merchantShortName']">
              <a-input v-model:value="jSubject.merchantShortName" placeholder="请输入" />
            </a-form-item>
          </a-col>
          <a-col class="gutter-row" :span="12">
            <a-form-item label="服务电话:" :name="['jSubject', 'servicePhone']">
              <a-input v-model:value="jSubject.servicePhone" placeholder="请输入" />
            </a-form-item>
          </a-col>
          <group-title class="pb-0.5" :iconOptions="{ class: 'text-blue-400' }">其他信息</group-title>
          <a-col class="gutter-row" :span="24">
            <a-form-item label="交易场景:" name="sceneTypeArr">
              <a-checkbox-group v-model:value="formData.sceneTypeArr" :options="scenesOptions" @change="handleSceneTypeArr" />
            </a-form-item>
          </a-col>
          <a-col class="gutter-row" :span="12" v-for="(item, index) in jSceneList" :key="item?.sceneType">
            <a-card size="small" :title="`${selectDictLabel(SCENES_TYPE_WECHAT, item?.sceneType)}场景`" class="w-full m-b-3">
              <!-- 线下 -->
              <div v-if="item?.sceneType == 0">
                <a-form-item label="门店名称:" :name="['jSceneList', index, 'name']">
                  <a-input v-model:value="item.name" placeholder="请输入" />
                </a-form-item>
                <a-form-item label="线下场所省市编码:" :name="['jSceneList', index, 'shopAddress1']">
                  <areaCascader @change="(val) => changeArea(val, item)" v-model:value="item.shopAddress1" :getMultiple="true" width="100%" />
                </a-form-item>
                <a-form-item label="线下场所地址:" :name="['jSceneList', index, 'url']">
                  <a-input v-model:value="item.url" placeholder="请输入详" />
                </a-form-item>
                <a-form-item label="线下场所对应的商家AppID:" :name="['jSceneList', index, 'appid']">
                  <a-input v-model:value="item.appid" placeholder="请输入" />
                </a-form-item>
                <a-form-item label="店铺内景图片" :name="['jSceneList', index, 'productUrl']">
                  <a-upload
                    v-model:file-list="item.productUrl"
                    name="productUrl"
                    :max-count="1"
                    :custom-request="(file) => uploadFunc(file, `jSceneList.${index}.productUrl`)"
                    :accept="limitUpload['comment'].fileType.toString()"
                    :before-upload="(file, fileList) => beforeUpload(file, fileList, 'productUrl')"
                    :headers="{
                      authorization: 'authorization-text',
                    }"
                  >
                    <a-button>
                      <upload-outlined />
                      点击上传
                    </a-button>
                  </a-upload>
                </a-form-item>
                <a-form-item label="店铺门头照图片:" :name="['jSceneList', index, 'indexUrl']">
                  <a-upload
                    v-model:file-list="item.indexUrl"
                    name="indexUrl"
                    :max-count="1"
                    :custom-request="(file) => uploadFunc(file, `jSceneList.${index}.indexUrl`)"
                    :accept="limitUpload['comment'].fileType.toString()"
                    :before-upload="(file, fileList) => beforeUpload(file, fileList, 'indexUrl')"
                    :headers="{
                      authorization: 'authorization-text',
                    }"
                  >
                    <a-button>
                      <upload-outlined />
                      点击上传
                    </a-button>
                  </a-upload>
                </a-form-item>
              </div>
              <!-- 服务号与公众号场景 -->
              <div v-if="item?.sceneType == 1">
                <a-form-item label="appId类型:" :name="['jSceneList', index, 'appidType']">
                  <a-select v-model:value="item.appidType" :options="APPID_TYPE" placeholder="请选择" />
                </a-form-item>
                <a-form-item label="商家服务号或公众号AppID:" :name="['jSceneList', index, 'appid']">
                  <a-input v-model:value="item.appid" placeholder="请输入" />
                </a-form-item>
                <a-form-item label="服务号或公众号页面截图:" :name="['jSceneList', index, 'indexUrl']">
                  <a-upload
                    v-model:file-list="item.indexUrl"
                    :max-count="5"
                    name="indexUrl"
                    :custom-request="(file) => uploadFunc(file, `jSceneList.${index}.indexUrl`)"
                    :accept="limitUpload['comment'].fileType.toString()"
                    :before-upload="(file, fileList) => beforeUpload(file, fileList, 'indexUrl')"
                    :headers="{
                      authorization: 'authorization-text',
                    }"
                  >
                    <a-button>
                      <upload-outlined />
                      点击上传
                    </a-button>
                  </a-upload>
                </a-form-item>
              </div>
              <!-- 小程序 -->
              <div v-if="item?.sceneType == 2">
                <a-form-item label="appId类型:" :name="['jSceneList', index, 'appidType']">
                  <a-select v-model:value="item.appidType" :options="APPID_TYPE" placeholder="请选择" />
                </a-form-item>
                <a-form-item label="商家小程序AppID:" :name="['jSceneList', index, 'appid']">
                  <a-input v-model:value="item.appid" placeholder="请输入" />
                </a-form-item>
                <a-form-item label="小程序截图:" :name="['jSceneList', index, 'indexUrl']">
                  <a-upload
                    v-model:file-list="item.indexUrl"
                    :max-count="5"
                    name="indexUrl"
                    :custom-request="(file) => uploadFunc(file, `jSceneList.${index}.indexUrl`)"
                    :accept="limitUpload['comment'].fileType.toString()"
                    :before-upload="(file, fileList) => beforeUpload(file, fileList, 'indexUrl')"
                    :headers="{
                      authorization: 'authorization-text',
                    }"
                  >
                    <a-button>
                      <upload-outlined />
                      点击上传
                    </a-button>
                  </a-upload>
                </a-form-item>
              </div>
              <!-- pc -->
              <div v-if="item?.sceneType == 3">
                <a-form-item label="互联网网站域名:" :name="['jSceneList', index, 'name']">
                  <a-input v-model:value="item.name" placeholder="请输入小程序名称" />
                </a-form-item>
                <a-form-item label="互联网网站对应的商家AppID:" :name="['jSceneList', index, 'appid']">
                  <a-input v-model:value="item.appid" placeholder="请输入" />
                </a-form-item>
                <a-form-item label="接入网址授权函:" :name="['jSceneList', index, 'authorizationUrl']">
                  <a-upload
                    v-model:file-list="item.authorizationUrl"
                    :max-count="1"
                    name="authorizationUrl"
                    :custom-request="(file) => uploadFunc(file, `jSceneList.${index}.authorizationUrl`)"
                    :accept="limitUpload['comment'].fileType.toString()"
                    :before-upload="(file, fileList) => beforeUpload(file, fileList, 'authorizationUrl')"
                    :headers="{
                      authorization: 'authorization-text',
                    }"
                  >
                    <a-button>
                      <upload-outlined />
                      点击上传
                    </a-button>
                  </a-upload>
                </a-form-item>
              </div>
              <!-- app -->
              <div v-if="item?.sceneType == 4">
                <a-form-item label="appId类型:" :name="['jSceneList', index, 'appidType']">
                  <a-select v-model:value="item.appidType" :options="APPID_TYPE" placeholder="请选择" />
                </a-form-item>
                <a-form-item label="商家应用AppID:" :name="['jSceneList', index, 'appid']">
                  <a-input v-model:value="item.appid" placeholder="请输入" />
                </a-form-item>
                <a-form-item label="App截图:" :name="['jSceneList', index, 'indexUrl']">
                  <a-upload
                    v-model:file-list="item.indexUrl"
                    :max-count="4"
                    name="indexUrl"
                    :custom-request="(file) => uploadFunc(file, `jSceneList.${index}.indexUrl`)"
                    :accept="limitUpload['comment'].fileType.toString()"
                    :before-upload="(file, fileList) => beforeUpload(file, fileList, 'indexUrl')"
                    :headers="{
                      authorization: 'authorization-text',
                    }"
                  >
                    <a-button>
                      <upload-outlined />
                      点击上传
                    </a-button>
                  </a-upload>
                </a-form-item>
                <p>请提供APP首页截图、尾页截图、应用内截图、支付页截图各1张</p>
              </div>
              <!-- 企业微信场景 -->
              <div v-if="item?.sceneType == 5">
                <a-form-item label="商家企业微信CorpID:" :name="['jSceneList', index, 'appid']">
                  <a-input v-model:value="item.appid" placeholder="请输入" />
                </a-form-item>
                <a-form-item label="企业微信页面截图:" :name="['jSceneList', index, 'payUrl']">
                  <a-upload
                    v-model:file-list="item.payUrl"
                    :max-count="5"
                    name="payUrl"
                    :custom-request="(file) => uploadFunc(file, `jSceneList.${index}.payUrl`)"
                    :accept="limitUpload['comment'].fileType.toString()"
                    :before-upload="(file, fileList) => beforeUpload(file, fileList, 'payUrl')"
                    :headers="{
                      authorization: 'authorization-text',
                    }"
                  >
                    <a-button>
                      <upload-outlined />
                      点击上传
                    </a-button>
                  </a-upload>
                </a-form-item>
              </div>
              <p>请上传图片信息，最小5KB ， 最大5M（暂不限制图片宽高）， 图片格式必须为：png、bmp、gif、jpg、jpeg</p>
            </a-card>
          </a-col>
        </a-row>
      </template>
      <template v-if="current === 3">
        <a-row :gutter="16">
          <a-col class="gutter-row" :span="24">
            <group-title class="pb-0.5" :iconOptions="{ class: 'text-blue-400' }">结算银行账户信息</group-title>
          </a-col>
          <a-col class="gutter-row" :span="12">
            <a-form-item label="账户类型:" :name="['jBankAccounts', 'bankAccountType']">
              <a-select
                v-model:value="jBankAccounts.bankAccountType"
                :options="REGIST_BANK_ACCOUNT_TYPE"
                placeholder="请选择"
                @change="changeBankAccountType"
              />
            </a-form-item>
          </a-col>
          <a-col class="gutter-row" :span="12">
            <a-form-item label="开户名称:" :name="['jBankAccounts', 'accountName']">
              <template #tooltip>
                <a-tooltip placement="top">
                  <template #title>
                    <div>1、选择“经营者个人银行卡”时，开户名称必须与“经营者证件姓名”一致；</div>
                    <div>2、选择“对公银行账户”时，开户名称必须与营业执照上的“商户名称”一致；</div>
                    <div>
                      3、该字段需要使用微信支付公钥加密（推荐），请参考获取微信支付公钥ID说明以及微信支付公钥加密敏感信息指引，也可以使用微信支付平台证书公钥加密，参考获取平台证书序列号、平台证书加密敏感信息指引。
                    </div>
                  </template>
                  <QuestionCircleOutlined /> </a-tooltip
              ></template>
              <a-input v-model:value="jBankAccounts.accountName" placeholder="请输入" />
            </a-form-item>
          </a-col>
          <a-col class="gutter-row" :span="12">
            <a-form-item label="开户银行:" :name="['jBankAccounts', 'accountBank']">
              <CustomSelect
                style="width: 100%"
                ref="bankRef"
                v-model:value="jBankAccounts.accountBank"
                :placeholder="'请选择'"
                :api="jBankAccounts.bankAccountType == '0' ? apiSource.getCorporateBanking : apiSource.getPersonalBanking"
                :queryParams="{ channelId: props.rowData.channelId }"
                @change="changeAccountBank"
                queryParamKey="nameLike"
                :valueField="'accountBank'"
                :labelField="'accountBank'"
              />
              <!-- 
                :initParams="{ code: jBankAccounts.accountBank }" -->
              <!-- <a-input v-model:value="jBankAccounts.accountName" placeholder="请输入" /> -->
            </a-form-item>
          </a-col>
          <!-- <a-col :span="12">
            <a-form-item label="开户行地区" :name="['jBankAccounts', 'bankAddressCode']">
              <template #tooltip>
                <a-tooltip placement="top">
                  <template #title>
                    <div>【开户银行省市编码】至少精确到市</div>
                  </template>
                  <QuestionCircleOutlined /> </a-tooltip
              ></template>
              <area-cascader style="width: 100%" v-model:value="jBankAccounts.bankAddressCode" @change="onBankAddressCodeChange" />
            </a-form-item>
          </a-col> -->
          <a-col class="gutter-row" :span="6">
            <a-form-item label="结算信息省份:" :name="['jBankAccounts', 'settleProvinceName']">
              <CustomSelect
                style="width: 100%"
                ref="bankRef"
                v-model:value="jBankAccounts.settleProvinceName"
                :placeholder="'请选择'"
                :api="apiSource.getProvinces"
                :queryParams="{
                  channelId: props.rowData.channelId,
                }"
                @change="changeProvince"
                queryParamKey="nameLike"
                :valueField="'name'"
              />
            </a-form-item>
          </a-col>
          <a-col class="gutter-row" :span="6">
            <a-form-item label="结算信息城市:" :name="['jBankAccounts', 'settleCityName']">
              <CustomSelect
                style="width: 100%"
                ref="bankRef"
                v-model:value="jBankAccounts.settleCityName"
                :placeholder="'请选择'"
                :api="apiSource.getCitys"
                :queryParams="{
                  channelId: props.rowData.channelId,
                  provinceCode: jBankAccounts.settleProvinceCode ?? '0',
                }"
                @change="changeCity"
                queryParamKey="nameLike"
                :valueField="'name'"
              />
            </a-form-item>
          </a-col>
          <a-col class="gutter-row" :span="12">
            <a-form-item label="开户银行全称（含支行）:" :name="['jBankAccounts', 'bankName']">
              <!-- <a-input v-model:value="jBankAccounts.bankName" placeholder="请输入" /> -->
              <CustomSelect
                style="width: 100%"
                ref="bankRef"
                v-model:value="jBankAccounts.bankName"
                :placeholder="'请选择'"
                :api="apiSource.getBranches"
                :queryParams="{
                  channelId: props.rowData.channelId,
                  cityCode: jBankAccounts.settleCityCode ?? -1,
                  bankAliasCode: jBankAccounts.bankAliasCode ?? -1,
                }"
                @focus="focusBankName"
                @change="changeBankName"
                queryParamKey="nameLike"
                :valueField="'bankBranchName'"
                :labelField="'bankBranchName'"
              />
            </a-form-item>
          </a-col>
          <a-col class="gutter-row" :span="12">
            <a-form-item label="开户银行银行号:" :name="['jBankAccounts', 'bankBranchId']">
              <a-input v-model:value="jBankAccounts.bankBranchId" placeholder="请输入" disabled />
            </a-form-item>
          </a-col>
          <a-col class="gutter-row" :span="12">
            <a-form-item label="银行账号:" :name="['jBankAccounts', 'accountNumber']">
              <a-input v-model:value="jBankAccounts.accountNumber" placeholder="请输入" />
            </a-form-item>
          </a-col>
          <a-col class="gutter-row" :span="24">
            <group-title class="pb-0.5" :iconOptions="{ class: 'text-blue-400' }">结算规则</group-title>
          </a-col>
          <!-- <a-col class="gutter-row" :span="12">
            <a-form-item label="入驻结算规则ID:" :name="['jBankAccounts', 'bankAccountType']">
              <a-select v-model:value="jBankAccounts.bankAccountType" :options="REGIST_BANK_ACCOUNT_TYPE" placeholder="请选择" />
            </a-form-item>
          </a-col> -->
          <a-col class="gutter-row" :span="12">
            <a-form-item label="一级经营类目:" :name="['jSubject', 'mccCodeOne']">
              <CustomSelect
                v-model:value="jSubject.mccCodeOne"
                :placeholder="'请先选择营业主体'"
                @change="changeMccCodeOne"
                :api="apiSource.businessPage"
                :searchFlag="false"
                :queryParams="headParams"
                :initParams="headInitParams"
                value-field="categoryCode"
                label-field="categoryName"
              />
            </a-form-item>
          </a-col>
          <a-col class="gutter-row" :span="12">
            <a-form-item label="二级经营类目:" :name="['jSubject', 'mccCodeTwo']">
              <CustomSelect
                v-model:value="jSubject.mccCodeTwo"
                :placeholder="'请先选择行业主体'"
                @change="changeMccCodeTwo"
                :api="apiSource.businessPage"
                :searchFlag="false"
                :queryParams="qualificationParams"
                value-field="categoryName"
                label-field="categoryName"
              />
              <!-- 
                :initParams="qualificationInitParams" -->
            </a-form-item>
          </a-col>
          <a-col class="gutter-row" :span="12">
            <a-form-item label="企业特殊资质图片:" :name="['jSubject', 'specialQualifications']">
              <a-upload
                v-model:file-list="jSubject.specialQualifications"
                :max-count="1"
                name="specialQualifications"
                :custom-request="(file) => uploadFunc(file, 'jSubject.specialQualifications')"
                :accept="limitUpload['comment'].fileType.toString()"
                :before-upload="(file, fileList) => beforeUpload(file, fileList, 'specialQualifications')"
                :headers="{
                  authorization: 'authorization-text',
                }"
              >
                <a-button>
                  <upload-outlined />
                  点击上传
                </a-button>
              </a-upload>
            </a-form-item>
          </a-col>
        </a-row>
      </template>
      <template v-if="current === 4">
        <a-row :gutter="16">
          <a-col class="gutter-row" :span="24">
            <group-title class="pb-0.5" :iconOptions="{ class: 'text-blue-400' }">补充材料</group-title>
          </a-col>
          <a-col class="gutter-row" :span="12">
            <a-form-item label="法人开户承诺函:" :name="['jSubject', 'legalPersonCommitment']">
              <a-upload
                v-model:file-list="jSubject.legalPersonCommitment"
                :max-count="1"
                name="legalPersonCommitment"
                :custom-request="(file) => uploadFunc(file, 'jSubject.legalPersonCommitment')"
                :accept="limitUpload['comment'].fileType.toString()"
                :before-upload="(file, fileList) => beforeUpload(file, fileList, 'legalPersonCommitment')"
                :headers="{
                  authorization: 'authorization-text',
                }"
              >
                <a-button>
                  <upload-outlined />
                  点击上传
                </a-button>
              </a-upload>
            </a-form-item>
          </a-col>
          <a-col class="gutter-row" :span="12">
            <a-form-item label="法人开户意愿视频:" :name="['jSubject', 'legalPersonVideo']">
              <a-upload
                v-model:file-list="jSubject.legalPersonVideo"
                :max-count="1"
                name="legalPersonVideo"
                :custom-request="(file) => uploadFunc(file, 'jSubject.legalPersonVideo')"
                :accept="limitUpload['legalPersonVideo'].fileType.toString()"
                :before-upload="(file, fileList) => beforeUpload(file, fileList, 'legalPersonVideo')"
                :headers="{
                  authorization: 'authorization-text',
                }"
              >
                <a-button>
                  <upload-outlined />
                  点击上传
                </a-button>
              </a-upload>
            </a-form-item>
          </a-col>
          <a-col class="gutter-row" :span="12">
            <a-form-item label="补充材料:" :name="['jSubject', 'businessAdditionPics']">
              <a-upload
                v-model:file-list="jSubject.businessAdditionPics"
                :max-count="5"
                name="businessAdditionPics"
                :custom-request="(file) => uploadFunc(file, 'jSubject.businessAdditionPics')"
                :accept="limitUpload['comment'].fileType.toString()"
                :before-upload="(file, fileList) => beforeUpload(file, fileList, 'businessAdditionPics')"
                :headers="{
                  authorization: 'authorization-text',
                }"
              >
                <a-button>
                  <upload-outlined />
                  点击上传
                </a-button>
              </a-upload>
            </a-form-item>
          </a-col>
          <a-col class="gutter-row" :span="24">
            <a-form-item label="补充说明:" :name="['jSubject', 'businessAdditionMsg']">
              <a-textarea v-model:value="jSubject.businessAdditionMsg" placeholder="请输入" show-count :maxlength="512" />
            </a-form-item>
          </a-col>
        </a-row>
      </template>
    </a-form>
    <template #footer>
      <div v-if="props.formType == 'updateScene'">
        <a-button key="back" @click="handleCancel"> 取消 </a-button>
        <a-button @click="handleSaveScene"> 保存 </a-button>
      </div>
      <div v-else-if="props.formType == 'view'">
        <a-button key="back" @click="handleCancel"> 取消 </a-button>
        <a-button type="primary" @click="previousStep" v-if="current !== 0"> 上一步 </a-button>
        <a-button type="primary" @click="nextStep" v-if="current !== stepsItems.length - 1"> 下一步 </a-button>
      </div>
      <div v-else>
        <a-button key="back" @click="handleCancel"> 取消 </a-button>
        <a-button @click="handleSave"> 保存 </a-button>
        <a-button @click="getHistoryData"> 调用进件资料 </a-button>
        <a-button type="primary" @click="previousStep" v-if="current !== 0"> 上一步 </a-button>
        <a-button type="primary" @click="nextStep" v-if="current !== stepsItems.length - 1"> 下一步 </a-button>
        <a-button key="submit" type="primary" @click="handleOk" v-if="current === stepsItems.length - 1"> 提交 </a-button>
      </div>
    </template>
  </a-modal>
</template>
<script setup name="WeChatForm">
  import { computed, onMounted, reactive, ref, watch, toRefs } from 'vue'
  import { message, Upload } from 'ant-design-vue'
  import { SmartLoading } from '/@/components/framework/smart-loading'
  import areaCascader from '/@/components/business/b-operation/area-cascader/index.vue'
  import SmartEnumSelect from '/@/components/framework/smart-enum-select/index.vue'
  import CustomSelect from '/@/components/business/comment/CustomSelect.vue'
  import { registApi } from '/@/api/business/b-operation/regist/index.js'
  import { registApi as agentRegistApi } from '/@/api/business/b-agent/regist/index.js'
  import { businessApi } from '/@/api/business/b-operation/regist/business.js'
  import { businessApi as agentBusinessApi } from '/@/api/business/b-agent/regist/business.js'
  import { isUndefined, cloneDeep, isEmpty } from 'lodash'
  import { convertPathsToFiles, getSelectedOptions, getObjValue, setObjValue, selectDictLabel, modifyFields, strToArr } from '/@/utils/common.js'
  import { isNum, validatePhoneNot } from '/@/utils/validate'
  import { myUpload } from '/@/utils/myUpload'
  import {
    SUBJECT_TYPE, // 主体类型
    SCENES_TYPE_WECHAT, //场景类型
    SERVICE_TYPE, //服务类型
    AUDIT_STATUS, //审核状态
    REGIST_BANK_ACCOUNT_TYPE, //银行账户类型
    HOLDER_TYPE, // 证件持有人类型
    DOC_TYPE, // 证件类型
    YES_OR_NO, // 是否
    FINANCE_TYPE, // 金融机构类型
    APPID_TYPE, // appid类型
  } from '/@/constants/dict'

  import { useUserStore } from '/@/store/modules/system/user'
  const USER_TYPE = useUserStore().userType // 用户类型: 1-平台;2-代理;4-商户

  const apiSource = {
    businessPage: (data) => {
      if (USER_TYPE == '2') return agentBusinessApi.page(data)
      if (USER_TYPE == '1') return businessApi.page(data)
    },
    detailPage: (data) => {
      if (USER_TYPE == '2') return agentRegistApi.detailPage(data)
      if (USER_TYPE == '1') return registApi.detailPage(data)
    },
    findId: (data) => {
      if (USER_TYPE == '2') return agentRegistApi.findId(data)
      if (USER_TYPE == '1') return registApi.findId(data)
    },
    save: (data) => {
      if (USER_TYPE == '2') return agentRegistApi.save(data)
      if (USER_TYPE == '1') return registApi.save(data)
    },
    insertScene: (data) => {
      if (USER_TYPE == '2') return agentRegistApi.insertScene(data)
      if (USER_TYPE == '1') return registApi.insertScene(data)
    },
    submit: (data) => {
      if (USER_TYPE == '2') return agentRegistApi.submit(data)
      if (USER_TYPE == '1') return registApi.submit(data)
    },
    findIdByChannelType: (data) => {
      if (USER_TYPE == '2') return agentRegistApi.findIdByChannelType(data)
      if (USER_TYPE == '1') return registApi.findIdByChannelType(data)
    },
    getPersonalBanking: (data) => {
      if (USER_TYPE == '2') return agentRegistApi.getPersonalBanking(data)
      if (USER_TYPE == '1') return registApi.getPersonalBanking(data)
    },
    getCorporateBanking: (data) => {
      if (USER_TYPE == '2') return agentRegistApi.getCorporateBanking(data)
      if (USER_TYPE == '1') return registApi.getCorporateBanking(data)
    },
    getBranches: (data) => {
      if (USER_TYPE == '2') return agentRegistApi.getBranches(data)
      if (USER_TYPE == '1') return registApi.getBranches(data)
    },
    getProvinces: (data) => {
      if (USER_TYPE == '2') return agentRegistApi.getProvinces(data)
      if (USER_TYPE == '1') return registApi.getProvinces(data)
    },
    getCitys: (data) => {
      if (USER_TYPE == '2') return agentRegistApi.getCitys(data)
      if (USER_TYPE == '1') return registApi.getCitys(data)
    },
  }

  const props = defineProps({
    open: {
      type: Boolean,
      default: false,
    },
    rowData: {
      type: Object,
      default: () => {
        return {
          id: '', //商户进件详情id(mpdId)
          channelType: '',
          apiType: '', //产品类型
        }
      },
    },
    // 表单类型 add/update/view
    // add: 新增, update: 编辑,view: 查看
    formType: {
      type: String,
      default: 'add',
    },
    formOptions: {
      type: Object,
      default: () => {
        return {
          layout: 'vertical',
          name: 'basic',
          autocomplete: 'off',
        }
      },
    },
    params: {
      type: Object,
      default: () => {
        return {}
      },
    },
  })

  const emit = defineEmits(['update:open', 'ok'])
  const openForm = computed({ get: () => props.open, set: (val) => emit('update:open', val) })

  // 步骤条
  const current = ref(0)
  const stepsItems = ref([
    {
      title: '超级管理员信息',
    },
    {
      title: '主体资料',
    },
    {
      title: '经营资料',
    },
    {
      title: '结算信息',
    },
    {
      title: '补充材料',
    },
  ])
  // 下一步
  const nextStep = async () => {
    let res = await validateForm()
    if (!res) return
    current.value >= stepsItems.value.length - 1 ? (current.value = stepsItems.value.length - 1) : current.value++
  }
  // 上一步
  const previousStep = () => {
    current.value <= 0 ? (current.value = 0) : current.value--
  }

  const alipayType = {
    0: '通用',
    1: '当面付',
  }

  // 图片字段
  const imgField = [
    'specialQualifications',
    'qualifications',
    'businessLicensePic',
    'financeLicensePics',
    'businessLicenseAuthPic',
    'indexUrl',
    'remarkUrl',
    'payUrl',
    'authorizationUrl',
    'productUrl',
    'idDocCopy',
    'idDocCopyBack',
    'authorizeLetterCopy',
    'businessAuthorizationLetter',
    'legalPersonCommitment',
    'legalPersonVideo',
    'businessAdditionPics',
  ]
  // 场景子表字段
  const jSceneListChild = {
    appMarket: undefined, //投放应用市场 0苹果 1应用宝 2华为 3 360 4小米 5豌豆夹 6其他
    merchantShortName: undefined, //商户简称
    servicePhone: undefined, //客服电话
    demoAccount: undefined, //测试用户
    type: undefined, //平台类型 0支付宝 1微信
    appidType: undefined, //appid类型
    appStatus: undefined, //应用状态 0未上线 1已上线
    url: undefined, //网站地址/门店详细地址/应用下载链接
    sId: undefined, //商户经营信息表编号
    merchantId: undefined, //商户编号
    sceneType: undefined, //场景类型 0线下 1服务号和公众号 2小程序 3pc 4app 5企业微信 6移动h5
    appid: undefined, //商户appID/企微corpId
    name: undefined, //小程序名称/应用名称/门店名称/网站名称
    shopCityCode: undefined, //市
    demoPass: undefined, //测试密码
    shopDistrictCode: undefined, //区县
    id: undefined, //编号
    shopProvinceCode: undefined, //省份
    indexUrl: [], //首页 小程序/h5网站/应用首页/门店门头/服务或公众号页面
    remarkUrl: [], //备注
    payUrl: [], //支付 h5网站/应用支付页/网站支付页/企微页面
    authorizationUrl: [], //授权 h5网站授权/app授权/接入网址授权
    productUrl: [], //商品 商品服务/网站商品页
  }
  // 商户身份信息子表字段
  const jIdentitiesListChild = {
    idHolderType: undefined, //证件持有人类型（LEGAL：经营者/法人；SUPER：经办人）
    idDocType: undefined, //证件类型: 0: 中国大陆居民-身份证 1: 其他国家或地区居民-护照 2: 中国香港居民-来往内地通行证 3: 中国澳门居民-来往内地通行证 4: 中国台湾居民-来往大陆通行证 5: 外国人居留证 6: 港澳居民证 7: 台湾居民证
    idDocName: undefined, //证件姓名
    idDocNumber: undefined, //证件号码
    idDocAddress: undefined, //证件居住地址
    idDocPeriodBegin: undefined, //证件有效期开始时间
    idDocPeriodEnd: undefined, //证件有效期结束时间
    idDocLongTermFlag: undefined, //证件是否长期有效
    userType: undefined, //用户类型 0超级管理员 1经营者/法人 2最终受益人
    owner: undefined, //是否受益人 0否1是
    businessAuthorizationLetter: [], //业务办理授权函（仅当 contact_type= SUPER 时填写）
    authorizeLetterCopy: [], //法定代表人说明函
    idDocCopy: [], //证件正面照片
    idDocCopyBack: [], //证件反面照片
  }
  const initData = {
    mpdId: undefined, //商户进件关联编号
    jBankAccounts: {
      channelId: undefined, //通道id
      bankAccountType: undefined, //银行账户类型 0: 对公银行账户 1: 经营者个人银行卡
      accountName: undefined, //账户名称
      accountBank: undefined, //开户银行
      bankAddressCode: undefined, //银行地址编码
      bankBranchId: undefined, //银行支行ID
      bankName: undefined, //银行名称
      accountNumber: undefined, //银行账号
      needBankBranch: undefined, //是否需要支行
      clearingBankCode: undefined, //结算账户清算⾏号
      settleProvinceCode: undefined, //结算信息省份代码
      settleProvinceName: undefined, //结算信息省份名称
      settleCityCode: undefined, //结算信息城市代码
      settleCityName: undefined, //结算信息城市名称
      serviceType: undefined, //服务类型：1代收；2代付；3自动分账；4不分账
      auditStatus: undefined, //审核状态：1待审核；2审核中；3审核通过；4审核拒绝
      auditMsg: undefined, //审核原因
      settlementType: undefined, //结算方式：1银行卡；2支付宝账号
      outCode: undefined, //外部编号
      utime: undefined, //可选
    }, //结算银行账户表
    jSubject: {
      financeInstitution: undefined, //是否为金融机构 0否1是
      businessLicenseMobile: undefined, //营业执照法人手机号
      merchantShortName: undefined, //商户简称
      dateLimitation: undefined, //营业期限
      settlementId: undefined, //结算规则ID
      subjectType: undefined, //主体类型： 0: 营业执照上的主体类型一般为个体户、个体工商户、个体经营 1: 营业执照上的主体类型一般为有限公司、有限责任公司 2: 包括各级、各类政府机关，如机关党委、税务、民政、人社、工商、商务、市监等 3:包括国内各级、各类政府机构、事业单位等。 如：公安、党团、司法、交通、旅游、工商税务、市政、医疗、教育、学校等机构 4: 包括社会团体、民办非企业、基金会、基层群众性自治组织、农村集体经济组织等组织
      mccCode: undefined, //经营类目
      mccCodeOne: undefined, //经营类目
      mccCodeTwo: undefined, //经营类目
      activitiesAdditions: undefined, //活动附加说明 用,拼接
      qualificationType: undefined, //所属行业类型
      qualifications: undefined, //特殊资质说明 用,拼接
      signAndAuth: undefined, //签约且授权标识，默认为false，只进行签约操作； 如果设置为true，则表示签约成功后，会自动进行应用授权操作。
      longTerm: 1, //营业执照是否长期有效 0否 1是
      activitiesId: undefined, //活动ID
      merchantId: undefined, //自定义商户编号
      rate: undefined, //服务费率（%），0.38~0.6 之间（小数点后两位，可取0.38%及0.6%）。 当签约且授权标识 sign_and_auth=true 时，该费率信息必填
      activitiesRate: undefined, //活动费率
      id: undefined, //编号
      debitActivitiesRate: undefined, //借记卡活动费率
      creditActivitiesRate: undefined, //信用卡活动费率
      email: undefined, //邮箱
      specialLicenseType: undefined, //特殊资质类型
      certificateLetterCopy: undefined, //单位证明函照片
      businessLicenseAddress: undefined, //营业执照的注册地址，若该字段未填写，系统将会查询国家工商信息填入。需注意若工商信息查询不到，则会被审核驳回。
      servicePhone: undefined, //服务电话
      businessAdditionMsg: undefined, //补充说明
      businessLicenseName: undefined, //营业执照商户名称
      businessLicenseNo: undefined, //营业执照号码
      phone: undefined, //手机号
      name: undefined, //姓名
      financeType: undefined, //金融机构类型 为金融机构时必传
      storeInfo: undefined, //销售场景
      account: undefined, //支付宝账号
      specialQualifications: [], //企业特殊资质图片
      businessLicensePic: [], //营业执照图片
      financeLicensePics: [], //金融机构许可证图片 用,拼接
      businessLicenseAuthPic: [], //营业执照授权函
      legalPersonCommitment: [], //法人开户承诺函1、请上传法定代表人或负责人亲笔签署的开户承诺函扫描件（下载模板）。亲笔签名承诺函内容清晰可见，不得有涂污，破损，字迹不清晰现象； 2、请填写通过图片上传API预先上传图片生成好的MediaID
      legalPersonVideo: [], //法人开户意愿视频 1、建议法人按如下话术录制“法人开户意愿视频”： 我是#公司全称#的法定代表人（或负责人），特此证明本公司申请的商户号为我司真实意愿开立且用于XX业务（或XX服务）。我司现有业务符合法律法规及腾讯的相关规定。 2、支持上传20M内的视频，格式可为avi、wmv、mpeg、mp4、mov、mkv、flv、f4v、m4v、rmvb； 3、请填写通过视频上传API预先上传视频生成好的MediaID 。
      businessAdditionPics: [], //补充材料 1、最多可上传5张照片； 2、请填写通过图片上传API预先上传图片生成好的MediaID。
    }, //商户经营信息表出参
    apiType: 1, //接口类型 0通用 1当面付
    jIdentitiesList: [], //商户身份信息
    jSceneList: [], //商户场景信息
    sceneTypeArr: [], //场景类型
  }
  const formData = reactive(cloneDeep(initData))
  const { jBankAccounts, jIdentitiesList, jSubject, jSceneList, sceneTypeArr } = toRefs(formData)

  const rules = ref({
    sceneTypeArr: [{ required: true, message: '交易场景 不能为空!', trigger: ['blur', 'change'] }], //交易场景
    jSubject: {
      account: [{ required: true, message: '商户号/支付宝账号不能为空!' }],
      name: [{ required: true, message: '姓名不能为空!' }],
      phone: [
        { required: true, message: '手机号码不能为空!' },
        {
          validator: validatePhoneNot,
        },
      ],
      email: [{ required: true, message: '联系邮箱不能为空!' }],
      mccCode: [{ required: true, message: '经营类目 不能为空!', trigger: ['blur', 'change'] }],
      mccCodeOne: [{ required: true, message: '经营类目 不能为空!', trigger: ['blur', 'change'] }],
      mccCodeTwo: [{ required: true, message: '经营类目 不能为空!', trigger: ['blur', 'change'] }],
      specialQualifications: [
        {
          required: computed(() => {
            return jSubject.value.specialLicenseType == '1'
          }),
          message: '企业特殊资质图片 不能为空!',
          trigger: ['blur', 'change'],
        },
      ],
      businessLicenseNo: [{ required: true, message: '营业执照号码 不能为空!', trigger: ['blur', 'change'] }],
      longTerm: [{ required: true, message: '营业期限是否长期有效 不能为空!', trigger: ['blur', 'change'] }],
      businessLicenseName: [{ required: true, message: '商户名称 不能为空!', trigger: ['blur', 'change'] }],
      financeType: [{ required: true, message: '金融机构类型 不能为空!', trigger: ['blur', 'change'] }],
      merchantShortName: [{ required: true, message: '商户简称 不能为空!', trigger: ['blur', 'change'] }],
      subjectType: [{ required: true, message: '商户简称 不能为空!', trigger: ['blur', 'change'] }],
      servicePhone: [{ required: true, message: '主体类型 不能为空!', trigger: ['blur', 'change'] }],
      businessLicensePic: [{ required: true, message: '营业执照照片 不能为空!', trigger: ['blur', 'change'] }],
    },
    jSceneList: computed(() => {
      let init = {
        appMarket: [{ required: true, message: '投放应用市场 不能为空!', trigger: ['blur', 'change'] }], //投放应用市场 0苹果 1应用宝 2华为 3 360 4小米 5豌豆夹 6其他
        merchantShortName: [{ required: true, message: '商户简称 不能为空!', trigger: ['blur', 'change'] }], //商户简称
        servicePhone: [{ required: true, message: '客服电话 不能为空!', trigger: ['blur', 'change'] }], //客服电话
        indexUrl: [{ required: true, message: '小程序/h5网站/应用首页/门店门头/服务或公众号页面 不能为空!', trigger: ['blur', 'change'] }], //首页 小程序/h5网站/应用首页/门店门头/服务或公众号页面
        payUrl: [{ required: true, message: 'h5网站/应用支付页/网站支付页/企微页面 不能为空!', trigger: ['blur', 'change'] }], //支付 h5网站/应用支付页/网站支付页/企微页面
        demoAccount: [{ required: true, message: '测试用户 不能为空!', trigger: ['blur', 'change'] }], //测试用户
        appStatus: [{ required: true, message: '应用状态 不能为空!', trigger: ['blur', 'change'] }], //应用状态 0未上线 1已上线
        url: [{ required: true, message: '网站地址/门店详细地址/应用下载链接 不能为空!', trigger: ['blur', 'change'] }], //网站地址/门店详细地址/应用下载链接
        sId: [{ required: true, message: '商户经营信息表编号 不能为空!', trigger: ['blur', 'change'] }], //商户经营信息表编号
        authorizationUrl: [{ required: true, message: '授权 不能为空!', trigger: ['blur', 'change'] }], //授权 h5网站授权/app授权/接入网址授权
        merchantId: [{ required: true, message: '商户编号 不能为空!', trigger: ['blur', 'change'] }], //商户编号
        productUrlM: [{ required: true, message: '图片 不能为空!', trigger: ['blur', 'change'] }], //商品 商品服务/网站商品页/店铺内景
        appid: [{ required: true, message: 'appID 不能为空!', trigger: ['blur', 'change'] }], //商户appID/企微corpId
        name: [{ required: true, message: '名称 不能为空!', trigger: ['blur', 'change'] }], //小程序名称/应用名称/门店名称/网站名称
        demoPass: [{ required: true, message: '测试密码 不能为空!', trigger: ['blur', 'change'] }], //测试密码
        appidType: [{ required: true, message: 'appid类型 不能为空!', trigger: ['blur', 'change'] }], //appid类型
        shopProvinceCode: [{ required: true, message: ' 不能为空!', trigger: ['blur', 'change'] }], //省份
        shopCityCode: [{ required: true, message: ' 不能为空!', trigger: ['blur', 'change'] }], //市
        shopDistrictCode: [{ required: true, message: ' 不能为空!', trigger: ['blur', 'change'] }], //区县
        shopAddress1: [{ required: true, message: '地址 不能为空!', trigger: ['blur', 'change'] }], //地址
        remarkUrl: [{ required: true, message: '备注 不能为空!', trigger: ['blur', 'change'] }], //备注
        id: [{ required: true, message: '编号 不能为空!', trigger: ['blur', 'change'] }], //编号
        productUrl: [{ required: true, message: '商品 不能为空!', trigger: ['blur', 'change'] }], //商品 商品服务/网站商品页
      }
      let arr = []
      if (jSceneList.value && jSceneList.value.length > 0) {
        jSceneList.value.forEach(() => {
          arr.push({ ...init })
        })
      } else {
        arr.push({ ...init })
      }
      return arr
    }),
    jIdentitiesList: computed(() => {
      let arr = []
      if (jIdentitiesList.value && jIdentitiesList.value.length > 0) {
        jIdentitiesList.value.forEach((item) => {
          arr.push({
            idHolderType: [{ required: true, message: '证件持有人类型 不能为空!', trigger: ['blur', 'change'] }],
            idDocType: [
              {
                required:
                  (item.userType == '0' && item.idHolderType == 'SUPER') ||
                  (item.userType == '1' && item.idHolderType == 'LEGAL') ||
                  item.userType == '2',
                message: '证件类型 不能为空!',
                trigger: ['blur', 'change'],
              },
            ],
            idDocName: [{ required: true, message: '证件姓名 不能为空!', trigger: ['blur', 'change'] }],
            idDocNumber: [
              {
                required: (item.userType == '0' && item.idHolderType == 'SUPER') || item.userType != '0',
                message: '证件号码 不能为空!',
                trigger: ['blur', 'change'],
              },
            ],
            idDocAddress: [
              {
                required: (item.userType == '1' && jSubject.value.subjectType == '1') || item.userType != '1',
                message: '证件居住地址 不能为空!',
                trigger: ['blur', 'change'],
              },
            ],
            idDocPeriodBegin: [
              {
                required: (item.userType == '0' && item.idHolderType == 'SUPER') || item.userType != '0',
                message: '证件有效期开始时间 不能为空!',
                trigger: ['blur', 'change'],
              },
            ],
            idDocPeriodEnd: [
              {
                required: (item.userType == '0' && item.idHolderType == 'SUPER') || item.userType != '0',
                message: '证件有效期结束时间 不能为空!',
                trigger: ['blur', 'change'],
              },
            ],
            idDocLongTermFlag: [{ required: true, message: '证件是否长期有效 不能为空!', trigger: ['blur', 'change'] }],
            userType: [{ required: true, message: '用户类型 不能为空!', trigger: ['blur', 'change'] }],
            owner: [
              { required: item.userType == '1' && jSubject.value.subjectType == '1', message: '是否受益人 不能为空!', trigger: ['blur', 'change'] },
            ],
            businessAuthorizationLetter: [
              { required: item.idHolderType == 'SUPER', message: '业务办理授权函 不能为空!', trigger: ['blur', 'change'] },
            ],
            authorizeLetterCopy: [{ required: item.idHolderType == 'SUPER', message: '法定代表人说明函 不能为空!', trigger: ['blur', 'change'] }],
            idDocCopy: [
              {
                required: (item.userType == '0' && item.idHolderType == 'SUPER') || item.userType != '0',
                message: '证件正面照片 不能为空!',
                trigger: ['blur', 'change'],
              },
            ],
            idDocCopyBack: [
              {
                required: (item.userType == '0' && item.idHolderType == 'SUPER') || item.userType != '0',
                message: '证件反面照片 不能为空!',
                trigger: ['blur', 'change'],
              },
            ],
          })
        })
      }
      return arr
    }),
    jBankAccounts: computed(() => {
      return {
        bankAccountType: [{ required: true, message: '账户类型 不能为空!', trigger: ['blur', 'change'] }],
        accountName: [{ required: true, message: '开户名称 不能为空!', trigger: ['blur', 'change'] }],
        accountBank: [{ required: true, message: '开户银行 不能为空!', trigger: ['blur', 'change'] }],
        bankAddressCode: [{ required: false, message: '开户行地区 不能为空!', trigger: ['blur', 'change'] }],
        bankBranchId: [{ required: false, message: '开户银行银行号 不能为空!', trigger: ['blur', 'change'] }],
        settleProvinceCode: [{ required: jBankAccounts.value.needBankBranch, message: '结算信息省份 不能为空!', trigger: ['blur', 'change'] }],
        settleCityCode: [{ required: jBankAccounts.value.needBankBranch, message: '结算信息城市 不能为空!', trigger: ['blur', 'change'] }],
        settleProvinceName: [{ required: jBankAccounts.value.needBankBranch, message: '结算信息省份 不能为空!', trigger: ['blur', 'change'] }],
        settleCityName: [{ required: jBankAccounts.value.needBankBranch, message: '结算信息城市 不能为空!', trigger: ['blur', 'change'] }],
        bankName: [{ required: jBankAccounts.value.needBankBranch, message: '开户银行全称（含支行） 不能为空!', trigger: ['blur', 'change'] }],
        accountNumber: [{ required: true, message: '银行账号 不能为空!', trigger: ['blur', 'change'] }, { validator: isNum }],
      }
    }),
  })

  const formRef = ref()
  const limitUpload = {
    comment: {
      fileType: ['.jpg', '.jpeg', '.png', '.bmp', '.gif'],
      fileSize: 2,
    },
    legalPersonVideo: {
      fileType: ['.avi', '.wmv', '.mpeg', '.mp4', '.mov', '.mkv', '.flv', '.f4v', '.m4v', '.rmvb'],
      fileSize: 5,
    },
  }
  const beforeUpload = (file, fileList, type) => {
    let limitUploadKeys = Object.keys(limitUpload)
    type = limitUploadKeys.includes(type) ? type : 'comment'
    // 校检文件类型
    if (limitUpload[type].fileType.length) {
      const fileExt = file.name.substring(file.name.lastIndexOf('.')).toLowerCase()
      const isTypeOk = limitUpload[type].fileType.includes(fileExt)
      if (!isTypeOk) {
        message.warning(`文件格式不正确, 请上传${limitUpload[type].fileType.toString().replace(/\./g, '').replace(/,/g, '、')}格式文件!`)
        return false || Upload.LIST_IGNORE
      }
    }

    // 校检文件大小
    if (limitUpload[type].fileSize) {
      const isLt = file.size / 1024 / 1024 < limitUpload[type].fileSize
      if (!isLt) {
        message.warning(`上传文件大小不能超过 ${limitUpload[type].fileSize} MB!`)
        return false || Upload.LIST_IGNORE
      }
    }

    return true
  }

  // 上传文件自定义的方法
  const uploadFunc = async (file, fieldName) => {
    // console.log('file==>', file)
    // 确保获取到文件对象
    const fileObj = file.file
    if (!fileObj) {
      return
    }
    const response = await myUpload(file)
    console.log('response==>', response)
    let arr = getObjValue(formData, fieldName).map((item) => {
      if (item.uid === fileObj.uid) {
        message.success(`${fileObj.name} 上传成功`)
        return response
      }
      return item
    })
    setObjValue(formData, fieldName, arr)
  }

  //校验表单
  const validateForm = async () => {
    let isValid = false
    try {
      await formRef.value.validate()
      isValid = true
    } catch (error) {
      message.warning(error.errorFields[0].errors)
      isValid = false
    }
    return isValid
  }

  //保存场景
  const handleSaveScene = async () => {
    validateForm().then(async (isValid) => {
      if (isValid) {
        let { jSceneList, mpdId } = formData
        const param = { jSceneList: cloneDeep(jSceneList), mpdId }
        imgInit(param)
        try {
          let res = await apiSource.insertScene(param)
          message.success('保存成功')
          emit('ok', formData)
          return res
        } catch (error) {
          console.error(error)
        }
      }
    })
  }
  //保存
  const handleSave = async () => {
    const param = { ...cloneDeep(formData), ...cloneDeep(props.params) }
    imgInit(param)
    try {
      let res = await apiSource.save(param)
      message.success('保存成功')
      emit('ok', formData)
      return res
    } catch (error) {
      console.error(error)
    }
  }

  //提交
  const handleOk = () => {
    // open.value = false
    validateForm().then((isValid) => {
      if (isValid) {
        handleSave().then(() => {
          const param = { checkStatus: 0, id: props.rowData.id }
          apiSource.submit(param).then(() => {
            message.success('提交成功')
            resetForm()
            emit('ok', formData)
            openForm.value = false
          })
        })
      }
    })
  }

  const handleCancel = () => {
    openForm.value = false
    resetForm()
    // open.value = false
  }
  const resetForm = () => {
    // 重置表单的 UI 状态
    try {
      formRef.value.resetFields()
    } catch (error) {
      console.error(error)
    }
    // 重置表单数据
    Object.assign(formData, cloneDeep(initData))
    // 重置步骤条
    current.value = 0
  }

  const areaFieldArr = ['shopProvinceCode', 'shopCityCode', 'shopDistrictCode']
  // 地址拆分
  const changeArea = (val, data) => {
    val.forEach((item, index) => {
      data[areaFieldArr[index]] = item
    })
  }
  // 地址合并
  function mergeArea(data) {
    data.jSceneList.forEach((item) => {
      if (item.sceneType == '0') {
        for (let i = 0; i <= areaFieldArr.length; i++) {
          if (!item[areaFieldArr[i]]) {
            item.shopAddress1 = item[areaFieldArr[i - 1]]
          }
        }
      }
    })
  }

  //调用进件资料
  function getHistoryData() {
    SmartLoading.show()
    let p = { id: props.rowData.id, channelType: props.rowData.channelType }
    apiSource
      .findIdByChannelType(p)
      .then((res) => {
        // jSubject/jSceneList
        if (isEmpty(res?.data)) return
        let resData = res.data
        imgInit(resData)
        mergeArea(resData)
        Object.assign(formData, resData)
        getSceneTypeArr()
        initFormList()
      })
      .finally(() => {
        SmartLoading.hide()
      })
  }
  // 获取表单数据
  function getFormData(data) {
    SmartLoading.show()
    let p = { mpdId: data.id, type: data.channelType }
    apiSource
      .findId(p)
      .then((res) => {
        // jSubject/jSceneList
        let resData = res.data
        resData.mpdId = data.id
        imgInit(resData)
        mergeArea(resData)
        Object.assign(formData, resData)
        getSceneTypeArr()
        initFormList()
      })
      .catch((err) => {
        // handleCancel()
        console.error(err)
        initFormList()
      })
      .finally(() => {
        SmartLoading.hide()
      })
  }
  // 图片初始化
  function imgInit(resData) {
    modifyFields(resData, imgField, (value, key) => {
      let val
      if (isEmpty(value)) return
      if (typeof value === 'string') {
        val = strToArr(value).map((item, index) => {
          return {
            uid: `db-file-${index}`,
            name: `${key}${index > 0 ? '_' + index : ''}`,
            status: 'done',
            url: item,
          }
        })
      }
      if (Array.isArray(value)) {
        val = value.map((e) => e.url).toString()
      }
      return val
    })
  }

  // 获取场景列表--场景初始化
  function getSceneTypeArr() {
    if (!isEmpty(jSceneList.value) && jSceneList.value.length > 0) {
      sceneTypeArr.value = [...new Set(jSceneList.value.map((item) => item.sceneType))]
    }
  }

  // 获取场景类型
  const handleSceneTypeArr = (val) => {
    sceneChange()
  }
  const sceneChange = () => {
    let sceneArr = jSceneList.value.map((item) => item?.sceneType)
    // formData.jSceneList.push({ ...cloneDeep(jSceneListChild), sceneType: 0 })
    formData.sceneTypeArr.forEach((item) => {
      if (!sceneArr.includes(item)) {
        formData.jSceneList.push({ ...cloneDeep(jSceneListChild), sceneType: item, type: props.rowData?.channelType })
      }
    })
    sceneArr.forEach((item, index) => {
      if (!formData.sceneTypeArr.includes(item)) {
        jSceneList.value.splice(index, 1)
      }
    })
  }

  /* 添加受益人、删除受益人 商户身份信息 */
  const addJIdentities = () => {
    let userType2 = formData.jIdentitiesList.reduce((count, item) => count + (item.userType === 2 ? 1 : 0), 0)
    if (userType2 < 4) {
      formData.jIdentitiesList.push({ ...cloneDeep(jIdentitiesListChild), userType: 2 })
    } else {
      message.warning('最多添加4个受益人')
    }
  }
  const delJIdentities = (index) => {
    formData.jIdentitiesList.splice(index, 1)
  }
  /* 添加受益人、删除受益人 商户身份信息 */

  // 改变账户类型
  const changeBankAccountType = () => {
    jBankAccounts.value.accountBank = undefined
    jBankAccounts.value.bankBranchId = undefined
  }
  // 改变开户银行(针对直连银行)
  const changeAccountBank = (val, opt) => {
    console.log('开户银行===>', opt)
    jBankAccounts.value.bankAliasCode = opt[0].bankAliasCode
    jBankAccounts.value.needBankBranch = opt[0].needBankBranch
    jBankAccounts.value.bankName = undefined
    // jBankAccounts.value.bankAddressCode = opt.map((e) => e.code).toString()
  }
  // 改变省份城市
  const changeProvince = (val, opt) => {
    jBankAccounts.value.settleProvinceCode = opt[0].code
    jBankAccounts.value.settleCityCode = undefined
    jBankAccounts.value.settleCityName = undefined
  }
  const changeCity = (val, opt) => {
    jBankAccounts.value.settleCityCode = opt[0].code
  }
  // 开户银行省市编码
  const onBankAddressCodeChange = (val, option) => {
    console.log('==>', val, option)
  }
  // 改变支行 开户银行全称（含支行）
  const changeBankName = (val, opt) => {
    // jBankAccounts.value.accountNumber = opt.map((e) => e.accountBankCode).toString()
    jBankAccounts.value.bankBranchId = opt[0].bankBranchId
  }
  const focusBankName = () => {
    if (!isEmpty(jBankAccounts.value.bankAliasCode)) return
    message.warning('请先选择开户银行')
    jBankAccounts.value.accountBank = undefined
  }

  // 主体类型
  const headParams = computed(() => {
    return {
      pCategoryCode: '000000',
      applicableMerchants: jSubject.value.subjectType,
    }
  })
  const headInitParams = computed(() => {
    return {
      categoryCode: jSubject.value.mccCodeOne,
    }
  })
  const qualificationParams = computed(() => {
    return {
      pCategoryCode: jSubject.value.mccCodeOne ? jSubject.value.mccCodeOne : 'unknown',
    }
  })
  const qualificationInitParams = computed(() => {
    return {
      categoryCode: jSubject.value.mccCodeTwo,
    }
  })
  // 切换行业一级类目
  const changeMccCodeOne = (val) => {
    jSubject.value.mccCodeTwo = undefined
  }
  // 切换行业二级类目
  const changeMccCodeTwo = (...val) => {
    // console.log(val)
    // 赋值费率
    jSubject.value.rate = val[1][0].rate
    // 获取规则id
    jSubject.value.settlementId = val[1][0].mccCode
    // 是否上传特殊资质
    jSubject.value.specialLicenseType = val[1][0].qualificationsType
  }

  function show(data) {
    if (data && !isEmpty(data)) {
      // Object.assign(formData, data)
      getFormData(data)
    }
  }

  /* 必填场景 */
  const requiredScene = computed(() => {
    return []
  })
  const scenesOptions = computed(() => {
    return SCENES_TYPE_WECHAT.map((item) => {
      return {
        ...item,
        disabled: requiredScene.value.includes(item.value),
        label: item.label,
        value: item.value,
      }
    })
  })

  /* 数组表单初始化 */
  function initFormList() {
    // 必填人员处理
    formData.mpdId = formData?.mpdId ?? props.rowData?.id
    // 确保 jIdentitiesList 存在且是数组
    if (!Array.isArray(formData.jIdentitiesList)) {
      formData.jIdentitiesList = []
    }
    const requiredUserTypes = [0, 1]
    // 一次性检查所需 userType 是否都存在
    const existingTypes = new Set(formData.jIdentitiesList.map((item) => item.userType))
    requiredUserTypes.forEach((userType) => {
      if (!existingTypes.has(userType)) {
        formData.jIdentitiesList.push({ ...cloneDeep(jIdentitiesListChild), userType })
      }
    })

    // 必填场景处理
    // requiredScene.value.forEach((item) => {
    //   if (formData.jSceneList.some((item) => item.sceneType == item)) return
    //   formData.jSceneList.push({ ...cloneDeep(jSceneListChild), sceneType: item, type: props.rowData?.channelType })
    // })
    // getSceneTypeArr()
  }
  watch(
    [() => props.rowData, () => props.open, () => props.params],
    (newVal) => {
      // apiType 判断通用还是当面付
      formData.apiType = props.params?.apiType || props.rowData?.apiType
      if ((props.formType == 'update' || props.formType == 'view') && props.open) {
        show(cloneDeep(newVal[0]))
      }
      if (props.formType == 'updateScene' && props.open) {
        // 修改场景
        show(cloneDeep(newVal[0]))
        current.value = 2
      }
      if (props.formType == 'add' && props.open && props.rowData?.id) {
        initFormList()
      }
    },
    { deep: true, immediate: true },
  )
  // watch([() => formData.sceneTypeArr], (newVal) => {}, { deep: true, immediate: true })
  // 在组件挂载时初始化地址选项
  onMounted(() => {})
  defineExpose({
    formRef,
  })
</script>
<style lang="scss" scoped></style>
